package com.webtest.demo;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;

import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;

import io.appium.java_client.AppiumBy;
import io.appium.java_client.android.AndroidDriver;

/**
 * author:zhuying
 *
 */


public class BaseDriver {

	static AndroidDriver driver;
	
	@BeforeClass
	public void initDriver() throws MalformedURLException {
		DesiredCapabilities cap = new DesiredCapabilities();
		URL url = new URL("http://127.0.0.1:4723/");
		cap.setCapability("platformName", "Android");
		cap.setCapability("appium:automationName", "uiautomator2");
		cap.setCapability("appium:deviceName", "127.0.0.1:62001");
		cap.setCapability("appPackage", "com.software.crossearth");
		cap.setCapability("appActivity", ".MainActivity");
		
		File file = new File("./apps/app-debug.apk");
//		cap.setCapability("appium:app", file.getAbsolutePath());
		cap.setCapability("appium:noReset",true);
		
	   driver = new AndroidDriver(url, cap);
	   driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));

//	   driver.findElement(AppiumBy
//				.xpath("//android.widget.TextView[@content-desc=\"CrossEarth\"]")).click();

	}
	
	@AfterClass
	public void quiteDriver() {
		if (driver != null) {
			driver.quit();
		}

	}
}
